<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/6/17
  Time: 13:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="/layui/css/layui.css" rel="stylesheet">
</head>
<body>
<!-- 给容器追加 class="layui-form-pane"，即可显示为方框风格 -->
<form class="layui-form layui-form-pane" action="/insertmessage">
    <div class="layui-form-item">
        <label class="layui-form-label">留言人</label>
        <div class="layui-input-block">
            <input type="text" name="username" autocomplete="off" placeholder="请输入" lay-verify="required"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">留言</label>
        <div class="layui-input-block">
            <textarea style="height:300px" name="content" placeholder="请输入留言内容"
                      class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item" align="center">
        <button class="layui-btn" lay-submit lay-filter="demo2">确认</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>

<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="/layui/layui.js"></script>
<script>
    layui.use(['form'], function () {

        var form = layui.form;
        var layer = layui.layer;
        // 提交事件
        form.on('submit(demo2)', function (data) {
            var field = data.field; // 获取表单字段值
            // 显示填写结果，仅作演示用
            alert("发布成功");
            // 此处可执行 Ajax 等操作
            // …
            return true; // 阻止默认 form 跳转
        });
    });
</script>

</body>
</html>
